capture log close

set matsize 5000



log using "LogFiles/ConfederatePatentAnalysis.log", replace

**** Basic Time Series Figures
use "Data/all_patents_basicinfo.dta", clear

**** Initial time series graphs for full database of patents
gen confederatestates = 0
replace confederatestates = 1 if inv_state1 == "tx" | inv_state1 == "ar" | inv_state1 == "la" | inv_state1 == "tn" | inv_state1 == "ms" | inv_state1 == "al" 
replace confederatestates = 1 if inv_state1 == "ga" | inv_state1 == "fl" | inv_state1 == "sc" | inv_state1 == "nc" | inv_state1 == "va"  
keep if confederatestates == 1

gen prosthetics = 0
replace prosthetics = 1 if nclassgoogle1 == 623

rename iyear year
keep patnum year nclassgoogle1 inv_state1 prosthetics
append using "Data/ConfederatePatentsCleaned.dta" 

keep if year >= 1855 & year <= 1875 

gen confederatepatent = 0
replace confederatepatent = 1 if patnum < 300
gen patentcount = 1
collapse (sum) patentcount, by(prosthetics year)
tsset prosthetics year
tsfill, full
replace patentcount = 0 if patentcount == .

// Panel B, Figure 1: Patent Time Series Contrasting Regions Directly Impacted by the US Civil War and World War I with Regions That Were Not
twoway (tsline patentcount if year >= 1855 & year <= 1875 & prosthetics == 1, xline(1862, lcolor(black) lpattern(dash)) xline(1867, lcolor(black) lpattern(dash)) lwidth(medthick)) (tsline patentcount if year >= 1855 & year <= 1875 & prosthetics != 1, yaxis(2) lpattern(dash) lwidth(medthick)), ytitle(Prosthetic Patents) ytitle(All Other Patents, axis(2)) title(Civil War Era Patents: Confederacy, color(black)) ylabel(0(2)8) ylabel(0(500)1500, axis(2)) xlabel(1855(5)1875) legend(label(1 "Prosthetics") label(2 "All Other")) graphregion(fcolor(white)) scale(0.9) name(LimbsVsOtherCivilWarConfederates, replace) 
graph export "Figures/LimbsVsOtherCivilWarConfederates.pdf", name(LimbsVsOtherCivilWarConfederates)  replace

capture log close



*** British patent counts for both wars
// Panel D, Figure 1: Patent Time Series Contrasting Regions Directly Impacted by the US Civil War and World War I with Regions That Were Not
import delimited using "Data/BritishPatents/WWI_Patent_Counts.csv", clear
tsset year
gen patentcount = count
twoway (tsline patentcount if year >= 1910 & year <= 1930, lwidth(medthick)), xline(1915, lcolor(black) lpattern(dash)) xline(1922, lcolor(black) lpattern(dash)) ytitle(Prosthetic Patents) title(World War I Era Prosthetic Patents: United Kingdom, color(black)) ylabel(0(15)60) xlabel(1910(5)1930) legend(label(1 "Prosthetics")) graphregion(fcolor(white)) scale(0.9) name(LimbsWorldWarIBritish, replace) 
graph export "Figures/LimbsWorldWarIBritish.pdf", name(LimbsWorldWarIBritish)  replace

// Panel E, Figure 1: Patent Time Series Contrasting Regions Directly Impacted by the US Civil War and World War I with Regions That Were Not
import delimited using "Data/BritishPatents/CW_Patent_Counts.csv", clear
tsset year
gen patentcount = count
twoway (tsline patentcount if year >= 1855 & year <= 1875, lwidth(medthick)), xline(1862, lcolor(black) lpattern(dash)) xline(1867, lcolor(black) lpattern(dash)) ytitle(Prosthetic Patents) title(Civil War Era Prosthetic Patents: United Kingdom, color(black)) ylabel(0(3)12) xlabel(1855(5)1875) legend(label(1 "Prosthetics")) graphregion(fcolor(white)) scale(0.9) name(LimbsCivilWarBritish, replace) 
graph export "Figures/LimbsCivilWarBritish.pdf", name(LimbsCivilWarBritish)  replace

// Panel F, Figure 1: Patent Time Series Contrasting Regions Directly Impacted by the US Civil War and World War I with Regions That Were Not
import delimited using "Data/SpanishPatents/CW_Spanish_Pat_Counts.csv", clear
rename publicationdate year
tsset year
gen patentcount = count
twoway (tsline patentcount if year >= 1855 & year <= 1875, lwidth(medthick)), xline(1862, lcolor(black) lpattern(dash)) xline(1867, lcolor(black) lpattern(dash)) ytitle(Prosthetic Patents) title(Civil War Era Prosthetic Patents: Spain, color(black)) ylabel(0(2)8) xlabel(1855(5)1875) legend(label(1 "Prosthetics")) graphregion(fcolor(white)) scale(0.9) name(LimbsCivilWarSpanish, replace) 
graph export "Figures/LimbsCivilWarSpanish.pdf", name(LimbsCivilWarSpanish)  replace



// Panel G, Figure 1: Patent Time Series Contrasting Regions Directly Impacted by the US Civil War and World War I with Regions That Were Not
*** Spanish patent counts for World War I
import delimited using "Data/SpanishPatents/WWI_Spanish_Pat_Counts.csv", clear
rename publicationdate year
tsset year
gen patentcount = count
twoway (tsline patentcount if year >= 1910 & year <= 1930, lwidth(medthick)), xline(1916, lcolor(black) lpattern(dash)) xline(1923, lcolor(black) lpattern(dash)) ytitle(Prosthetic Patents) title(World War I Era Prosthetic Patents: Spain, color(black)) ylabel(0(7.5)30) xlabel(1910(5)1930) legend(label(1 "Prosthetics")) graphregion(fcolor(white)) scale(0.9) name(LimbsWorldWarISpanish, replace) 
graph export "Figures/LimbsWorldWarISpanish.pdf", name(LimbsWorldWarISpanish)  replace




*** British patent traits simple-diff for WWI
// Generates column (5), Table 5:
import delimited using "Data/Brit_LimbKeywordSearchEncodings.csv", clear

gen user = (comfort + appearance + appliances)/3  
gen production = (adjustability + simplicity + cost)/3 
gen anyproduction = max(adjustability, simplicity, cost, materials) 


gen period = .
replace period = 0 if year >= 1900 & year <= 1914
replace period = 1 if year >= 1915 & year <= 1922
drop if period == .
gen patentcount = 1
collapse (sum) patentcount (mean) comfort adjustability simplicity cost appearance materials appliances durability user production, by(period)
drop if period == .
gen unit = 1
reshape wide patentcount comfort adjustability simplicity cost appearance materials appliances durability user production, i(unit) j(period) 

foreach trait in appearance comfort simplicity cost adjustability materials appliances durability production user {
	gen simpdiffestimate`trait' = `trait'1 - `trait'0
	drop `trait'1 `trait'0
}

drop patentcount*

reshape long simpdiffestimate, i(unit) j(trait) string

save "Data/simplediffresults/simplediffbritishpatentsWWI.dta", replace





